package com.macro.mall.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.BmsExhibitionsActivitiesGoodsParam;
import com.macro.mall.model.BmsExhibitionsActivitiesGoods;
import com.macro.mall.service.BmsExhibitionsActivitiesGoodsService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 展览活动展品Controller Created by macro on 2018/4/26.
 */
@Controller
@Api(tags = "BmsExhibitionsActivitiesGoodsController")
@Tag(name = "BmsExhibitionsActivitiesGoodsController", description = "展览活动-展品管理")
@RequestMapping("/exhibitionsActivitiesGoods")
public class BmsExhibitionsActivitiesGoodsController {
    @Autowired
    private BmsExhibitionsActivitiesGoodsService bmsExhibitionsActivitiesGoodsService;

    @ApiOperation("添加展览活动展品")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> create(@RequestBody BmsExhibitionsActivitiesGoodsParam bmsExhibitionsActivitiesGoodsParam) {
        int count = bmsExhibitionsActivitiesGoodsService.create(bmsExhibitionsActivitiesGoodsParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

    @ApiOperation("修改展览活动")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> update(@RequestBody BmsExhibitionsActivitiesGoodsParam bmsExhibitionsActivitiesGoodsParam) {
        int count = bmsExhibitionsActivitiesGoodsService.update(bmsExhibitionsActivitiesGoodsParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

    @ApiOperation("分页查询展览活动")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<BmsExhibitionsActivitiesGoods>> getList(
            @RequestBody BmsExhibitionsActivitiesGoodsParam bmsExhibitionsActivitiesGoodsParam) {
        List<BmsExhibitionsActivitiesGoods> bmsExhibitionsActivitiesGoodsList = bmsExhibitionsActivitiesGoodsService
                .getList(bmsExhibitionsActivitiesGoodsParam);
        return CommonResult.success(CommonPage.restPage(bmsExhibitionsActivitiesGoodsList));
    }

    @ApiOperation("根据id获取展览活动信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<BmsExhibitionsActivitiesGoods> getItem(@PathVariable Long id) {
        BmsExhibitionsActivitiesGoods bmsExhibitionsActivitiesGoods = bmsExhibitionsActivitiesGoodsService.getItem(id);
        return CommonResult.success(bmsExhibitionsActivitiesGoods);
    }

    @ApiOperation("删除展览活动")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> delete(@RequestBody List<Long> ids) {
        int count = bmsExhibitionsActivitiesGoodsService.delete(ids);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }
}
